UC-SLS Lecture 9 : Assembly : Operations and Data Types
Contents
UC-SLS Lecture 9 : Assembly : Operations and Data Types¶
A simple mov.S program¶
Setup¶
create a directory
mkdir mov; cd movcreate and write
mov.Sbelowadd a
Makefileto automate assembling and linkingwe are going run the commands by hand this time to highlight the details
add our
setup.gdbto make working in gdb easiernormally you would want to track everything in git
CODE: asm - mov.S
.intel_syntax noprefix
.text
.equ EXIT_SYSCALL_NR,60
.global _start
.type _start, @function
_start:
mov rax, 0b1000
mov rax, EXIT_SYSCALL_NR
mov rdi, 2
syscall
Assemble mov.S into mov.o directly with assembler (as)¶
-aproduce listing to standard outwe could add
-gflag to add extra debugger information but lets skip it for now
mov.o is NOT an executable¶
What kind of file is is it?¶
Examine Symbol Table¶
Link mov.o to produce the binary mov with linker (ld)¶
we don’t really have any other files to link
simply need to have linker organize things as per os linker script (use
ld -verboseto see the script )note the syntax is very cryptic
recognize anything?¶
lets run it¶
We can use tools to convert the executable into a binary image¶
objcopyis a very useful tool likeobjdumplet’s us convert the executable into various formats including
rawbinaryobjcopy mov --output-target=binary mov.bin